package cloud.xlh.infrastructure.enums;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/3/26 11:49
 * @ Description:
 */
public enum DataSourceEnum {
    MASTER(00, "master"),
    SLAVE_1(01, "slave_1"),
    SLAVE_2(10, "slave_2"),
    SLAVE_3(11, "slave_3");

    private static final Set<Integer> enumSet = new HashSet<>(4);

    static {
        Arrays.asList(DataSourceEnum.values()).forEach(e -> enumSet.add(e.getCode()));
    }

    public static boolean hasEnum(Integer code) {
        return enumSet.contains(code);
    }


    private Integer code;

    private String desc;

    DataSourceEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static String getDesc(Integer code) {
        DataSourceEnum[] values = values();
        if (code == null)
            return null;
        for (DataSourceEnum value : values) {
            if (value.code.equals(code)) {
                return value.desc;
            }
        }
        return null;
    }
}
